package org.yuanqiframework.yuanqi.boot.sys.controller;

import org.yuanqiframework.yuanqi.web.controller.BaseController;
import org.yuanqiframework.yuanqi.web.entity.AjaxResult;
import org.yuanqiframework.yuanqi.web.utils.WebUploadFileUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

@Slf4j
@RestController
@RequestMapping("/api/sys/file")
public class FileController extends BaseController {

    @PostMapping("upload")
    public AjaxResult<String> upload(MultipartFile file) throws IOException {
        File uploadFile = WebUploadFileUtils.upload(file);
        return AjaxResult.success(WebUploadFileUtils.UPLOAD_PATH_DIR_NAME + File.separator + uploadFile.getName());
    }
}
